package com.example;

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.task.configuration.EnableTask;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
@EnableTask//By default, it imports an additional configuration class (SimpleTaskConfiguration).
//This additional configuration registers the TaskRepository and the infrastructure for its use.
//Out of the box, the TaskRepository uses an in-memory Map to record the results of a task
//Creating: TaskExecution{executionId=0, parentExecutionId=null, exitCode=null, taskName='helloWorld', startTime=Tue Jul 14 23:42:46 GMT+08:00 2020, endTime=null, exitMessage='null', externalExecutionId='null', errorMessage='null', arguments=[]}
public class SampleTask {

    @Bean
    public CommandLineRunner commandLineRunner() {
        return new HelloWorldCommandLineRunner();
    }

    public static void main(String[] args) {
        SpringApplication.run(SampleTask.class, args);
    }

    public static class HelloWorldCommandLineRunner implements CommandLineRunner { // or implements ApplicationRunner

        @Override
        public void run(String... strings) throws Exception {
            System.out.println("Hello, World!");
        }
    }
}